package com.atguigu.tingshu.order.adapter.impl;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.order.adapter.PayWay;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author codingyz
 * @Description
 * @date 2025/3/28 18:55
 * @Version 1.0
 */
@Service
@Slf4j
public class WxPayWayImpl implements PayWay {

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private RabbitService rabbitService;

    @Override
    public boolean isSupport(String payWay) {
        return "1101".equals(payWay);
    }

    @Override
    public void dealPayWay(OrderInfoVo orderInfoVo, Long userId, String orderNo) {

        // 微信支付
        // 1.保存订单相关信息
        orderInfoService.saveOrderInfo(userId, orderInfoVo, orderNo);

        // 2.延时关单
        // 2.1延时30min 关单 给延时交换机发送消息
        rabbitService.sendDealyMessage(MqConst.EXCHANGE_CANCEL_ORDER, MqConst.ROUTING_CANCEL_ORDER, orderNo, 60);// 60s 测试用
    }
}
